package com.example.controller;

import com.example.model.UserCRUD;

import android.telephony.SmsManager;

public class SMSUtility {
	private int receiverUserID;
	private String message;
	
	public SMSUtility(int receiver, String message){
		this.receiverUserID = receiver;
		this.message = message;
	}

	public void sendSMS(){
		
		User receivingUser = new User(new UserCRUD());
		
		receivingUser = receivingUser.read(this.receiverUserID);
		
		String receivingNumber = receivingUser.getPhone();		
		
		System.out.println("IN SEND SMS");
		try{
			if(receivingNumber != "null" && receivingNumber != ""){
				SmsManager sm = SmsManager.getDefault();
				sm.sendTextMessage(receivingNumber, null, this.message, null, null);
				System.out.println("Sending Message to " + receivingNumber);
			}
			else
			{
				System.out.println("Message not sent");
			}
		}
		catch (Exception e){
			System.out.println("SMS failed!");
			e.printStackTrace();
		}
		finally{
			System.out.println("Done with SMSUtility.sendSMS");
		}
		
		
	}
	
	public int getReceiverUserID() {
		return this.receiverUserID;
	}

	public void setReceiverUserID(int receiverUserID) {
		this.receiverUserID = receiverUserID;
	}

	public String getMessage() {
		return this.message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	
}
